<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Redis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="1.redis查看配置12345678910[root@redis ~]# redis-cli127.0.0.1:6379&amp;gt; CONFIG get *         # 查看所有配置项127.0.0.1:6379&amp;gt; CONFIG get timeout   # 查看timeout1) &quot;timeout&quot;2) &quot;300&quot;127.0.0.1:6379&amp;gt; CONFIG set tim">
<meta name="keywords" content="Redis">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis 配置文件">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/Redis/2. Redis 配置文件/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="1.redis查看配置12345678910[root@redis ~]# redis-cli127.0.0.1:6379&amp;gt; CONFIG get *         # 查看所有配置项127.0.0.1:6379&amp;gt; CONFIG get timeout   # 查看timeout1) &quot;timeout&quot;2) &quot;300&quot;127.0.0.1:6379&amp;gt; CONFIG set tim">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-02T17:30:38.299Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Redis 配置文件">
<meta name="twitter:description" content="1.redis查看配置12345678910[root@redis ~]# redis-cli127.0.0.1:6379&amp;gt; CONFIG get *         # 查看所有配置项127.0.0.1:6379&amp;gt; CONFIG get timeout   # 查看timeout1) &quot;timeout&quot;2) &quot;300&quot;127.0.0.1:6379&amp;gt; CONFIG set tim">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/Redis/2. Redis 配置文件/"/>





  <title>Redis 配置文件 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/Redis/2. Redis 配置文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Redis 配置文件</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:09:22+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1-redis查看配置"><a href="#1-redis查看配置" class="headerlink" title="1.redis查看配置"></a>1.redis查看配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@redis ~]<span class="comment"># redis-cli</span></div><div class="line">127.0.0.1:6379&gt; CONFIG get *         <span class="comment"># 查看所有配置项</span></div><div class="line">127.0.0.1:6379&gt; CONFIG get timeout   <span class="comment"># 查看timeout</span></div><div class="line">1) <span class="string">"timeout"</span></div><div class="line">2) <span class="string">"300"</span></div><div class="line">127.0.0.1:6379&gt; CONFIG <span class="built_in">set</span> timeout 0 <span class="comment"># 重设 timeout</span></div><div class="line">OK</div><div class="line">127.0.0.1:6379&gt; CONFIG get timeout</div><div class="line">1) <span class="string">"timeout"</span></div><div class="line">2) <span class="string">"0"</span></div></pre></td></tr></table></figure>
<h2 id="2-redis-通用配置"><a href="#2-redis-通用配置" class="headerlink" title="2.redis 通用配置"></a>2.redis 通用配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">daemonize no                  <span class="comment"># 默认情况下，redis并不是以daemon形式来运行的。通过daemonize配置项可以控制redis的运行形式</span></div><div class="line">pidfile /path/to/redis.pid    <span class="comment"># 当以daemon形式运行时，redis会生成一个pid文件，默认会生成在/var/run/redis.pid</span></div><div class="line"><span class="built_in">bind</span> 192.168.1.2 10.8.4.2     <span class="comment"># 指定绑定的ip，可以有多个</span></div><div class="line">port 6379                     <span class="comment"># 指定监听端口</span></div><div class="line">unixsocket /tmp/redis.sock    <span class="comment"># 也可以监听socket</span></div><div class="line">unixsocketperm 755            <span class="comment"># 当监听socket时可以指定权限为755</span></div><div class="line">timeout 0                     <span class="comment"># 当一个redis-client一直没有请求发向server端，那么server端有权主   动关闭这个连接，可以通过timeout来设置“空闲超时时限”，0表示永不关闭。</span></div><div class="line">tcp-keepalive 0               <span class="comment"># TCP连接保活策略，可以通过tcp-keepalive配置项来进行设置，单位为秒，假如设置为60秒，则server端会每60秒向连接空闲的客户端发起一次ACK请求，以检查客户端是否已经挂掉，对于无响应的客户端则会关闭其连接。如果设置为0，则不会进行保活检测。</span></div><div class="line">loglevel notice               <span class="comment"># 日志级别，有四种debug, verbose, notice, warning</span></div><div class="line">logfile “”                    <span class="comment"># 定义日志路径，</span></div><div class="line">syslog-ident redis            <span class="comment"># 如果希望日志打印到syslog中，通过syslog-enabled来控制。另外，syslog-ident还可以让你指定syslog里的日志标志。</span></div><div class="line">syslog-facility local0        <span class="comment"># 指定syslog的设备，可以是USER或者local0-local7</span></div><div class="line">databases 16                  <span class="comment"># 设置数据库的总数量</span></div></pre></td></tr></table></figure>
<h2 id="3-redis-快照配置（rdb持久化）"><a href="#3-redis-快照配置（rdb持久化）" class="headerlink" title="3.redis 快照配置（rdb持久化）"></a>3.redis 快照配置（rdb持久化）</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">save 900 1                      <span class="comment"># 表示每15分钟且至少有1个key改变，就触发一次持久化 </span></div><div class="line">save 300 10                     <span class="comment"># 表示每5分钟且至少有10个key改变，就触发一次持久化</span></div><div class="line">save 60 10000                   <span class="comment"># 表示每60秒至少有10000个key改变，就触发一次持久</span></div><div class="line">save “”                         <span class="comment"># 这样可以禁用rdb持久化</span></div><div class="line">stop-writes-on-bgsave-error yes <span class="comment"># rdb持久化写入磁盘避免不了会出现失败的情况，默认一旦出现失败，redis会马上停止写操作。如果你觉得无所谓，那就可以使用该选项关闭这个功能。</span></div><div class="line">rdbcompression yes              <span class="comment"># 是否要压缩</span></div><div class="line">rdbchecksum yes                 <span class="comment"># 是否进行数据校验</span></div><div class="line">dbfilename dump.rdb             <span class="comment"># 定义快照文件的名字</span></div><div class="line">dir ./                          <span class="comment"># 定义快照文件储存路劲</span></div></pre></td></tr></table></figure>
<h2 id="4-redis-安全相关配置"><a href="#4-redis-安全相关配置" class="headerlink" title="4.redis 安全相关配置"></a>4.redis 安全相关配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">requirepass yanyi                      <span class="comment"># 设置redis-server的密码</span></div><div class="line">rename-command CONFIG  yanyi.config    <span class="comment"># 将CONFIG命令更名为yanyi.config，这样可以避免误操作，但如果使用了    AOF持久化，建议不要启用该功能</span></div><div class="line">rename-command CONFIG “”               <span class="comment"># 也可以后面定义为空，这样就禁掉了该CONFIG命令</span></div></pre></td></tr></table></figure>
<h2 id="5-redis-限制相关配置"><a href="#5-redis-限制相关配置" class="headerlink" title="5.redis 限制相关配置"></a>5.redis 限制相关配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">maxclients 10000              <span class="comment"># 限制最大客户端连接数</span></div><div class="line">maxmemory &lt;bytes&gt;             <span class="comment"># 设定最大内存使用数，单位是byte</span></div><div class="line">maxmemory-policy volatile-lru <span class="comment"># 指定内存移除规则</span></div><div class="line">maxmemory-samples 3           <span class="comment"># LRU算法和最小TTL算法都并非是精确的算法，而是估算值。所以你可以设置样本的大小。假如redis默认会检查三个key并选择其中LRU的那个，那么你可以改变这个key样本的数量。</span></div></pre></td></tr></table></figure>
<h2 id="6-redis-AOF-持久化相关配置"><a href="#6-redis-AOF-持久化相关配置" class="headerlink" title="6.redis AOF 持久化相关配置"></a>6.redis AOF 持久化相关配置</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">appendonly no                   <span class="comment"># 如果是no，则开启aof持久化</span></div><div class="line">appendfilename “appendonly.aof” <span class="comment"># 指定aof文件名字</span></div><div class="line">appendfsync everysec            <span class="comment"># 指定fsync()调用模式，有三种no(不调用fsync),always(每次写都会调用fsync),everysec(每秒钟调用一次fsync)。第一种最快，第二种数据最安全，但性能会差一些，第三种为这种方案，默认为第三种。</span></div><div class="line">no-appendfsync-on-rewrite no    <span class="comment"># 设置yes，可避免当写入量非常大时的磁盘io阻塞</span></div><div class="line">auto-aof-rewrite-percentage 10  <span class="comment"># 规定什么情况下会触发aof重写。该值为一个比例，10表示当aof文件增幅达到10%时则会触发重写机制。</span></div><div class="line">uto-aof-rewrite-min-size 64mb   <span class="comment"># 重写会有一个条件，就是不能低于64Mb</span></div></pre></td></tr></table></figure>
<h2 id="7-redis-慢日志相关配置"><a href="#7-redis-慢日志相关配置" class="headerlink" title="7.redis 慢日志相关配置"></a>7.redis 慢日志相关配置</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;针对慢日志，你可以设置两个参数，一个是执行时长，单位是微秒，另一个是慢日志的长度。当一个新的命令被写入日志时，最老的一条会从命令日志队列中被移除。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">slowlog-log-slower-than 10000  <span class="comment"># 慢于10000ms则记录日志</span></div><div class="line">slowlog-max-len 128            <span class="comment"># 日志长度</span></div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Redis/" rel="tag"># Redis</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/Redis/20. Redis 列表(List)/" rel="next" title="Redis 列表(List)">
                <i class="fa fa-chevron-left"></i> Redis 列表(List)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Redis/21. Redis 集合(Set)/" rel="prev" title="Redis 集合(Set)">
                Redis 集合(Set) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-redis查看配置"><span class="nav-number">1.</span> <span class="nav-text">1.redis查看配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-redis-通用配置"><span class="nav-number">2.</span> <span class="nav-text">2.redis 通用配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-redis-快照配置（rdb持久化）"><span class="nav-number">3.</span> <span class="nav-text">3.redis 快照配置（rdb持久化）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-redis-安全相关配置"><span class="nav-number">4.</span> <span class="nav-text">4.redis 安全相关配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-redis-限制相关配置"><span class="nav-number">5.</span> <span class="nav-text">5.redis 限制相关配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-redis-AOF-持久化相关配置"><span class="nav-number">6.</span> <span class="nav-text">6.redis AOF 持久化相关配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-redis-慢日志相关配置"><span class="nav-number">7.</span> <span class="nav-text">7.redis 慢日志相关配置</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
